package com.dawn.module.cms.api.department;

import com.dawn.framework.common.pojo.PageParam;
import com.dawn.framework.common.util.object.BeanUtils;
import com.dawn.module.cms.api.department.dto.CmsDepartmentRespDTO;
import com.dawn.module.cms.controller.admin.department.vo.DepartmentPageReqVO;
import com.dawn.module.cms.dal.dataobject.department.DepartmentDO;
import com.dawn.module.cms.service.department.DepartmentService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;


/**
 * 科室的 API 实现类
 *
 * @author dawn
 */
@Service
@Validated
public class CmsDepartmentApiImpl implements CmsDepartmentApi {


    @Resource
    private DepartmentService departmentService;

    @Override
    public CmsDepartmentRespDTO getDepartment(Long id) {
        DepartmentDO department = departmentService.getDepartment(id);
        return BeanUtils.toBean(department, CmsDepartmentRespDTO.class);
    }

    @Override
    public List<CmsDepartmentRespDTO> getList() {
        DepartmentPageReqVO pageReqVO = new DepartmentPageReqVO();
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DepartmentDO> list = departmentService.getDepartmentPage(pageReqVO).getList();
        return BeanUtils.toBean(list, CmsDepartmentRespDTO.class);
    }

    @Override
    public List<CmsDepartmentRespDTO> getListByName(String name) {
        DepartmentPageReqVO pageReqVO = new DepartmentPageReqVO();
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        pageReqVO.setName(name);
        List<DepartmentDO> list = departmentService.getDepartmentPage(pageReqVO).getList();
        return BeanUtils.toBean(list, CmsDepartmentRespDTO.class);
    }
}
